<?php
Yii::import('zii.widgets.CPortlet');
class BookComment extends CPortlet{
	
	public $bid; //图书id
	public $num; //显示的评论条数
	
	public function init(){
		parent::init();
		}
		
	public function renderContent(){
		$commentlist = $this->getContentList($this->bid,$this->num);
		
		$html = '';
		foreach($commentlist as $key=>$comment){
		$userimg = bu().'/ucenter/data/avatar/000/00/00/0'.$comment->uid.'_avatar_small.jpg';
		if(!file_exists(bp().'/../ucenter/data/avatar/000/00/00/0'.$comment->uid.'_avatar_small.jpg')){
			$userimg = bu().'/ucenter/images/noavatar_small.gif';
		}
			$commententry = UrCommentEntry::model()->find('cid=:cid',array(':cid'=>$comment->id));
			$html .="<div class='comment_left_colum'>".CHtml::image($userimg)."</div><div class='comment_right_colum'>";
			$html .= "<div class='comment_title'>$comment->subject</div>";
			$html .="<div class='comment_author'><span class='bluename'>$comment->username</span>&nbsp;&nbsp;<span style='color:gray'>".date('Y-m-d',$comment->create_datetime)."</span><br/></div>";
			$html .="<div class='comment_content'>$commententry->content</div>";
			$html .="<br/><br/></div>";
		}
		echo $html;
		}	
	/**
	 * 获取评论列表
	 * @params int $bid 图书id
	 * @params int $num 显示的图书条数
	 */	
	public function getContentList($bid,$num){
		$comment = UrComment::model()->findAll(array(
			'condition'=>'bid=:bid and parentId=0',
			'params'=>array(':bid'=>$bid),
			'limit'=>$num,
			'order'=>'create_datetime desc',
		));
		if($comment===null)	return '暂无评论';
		else return $comment;
		}
		

	}
